package com.yl.project.lvyou.knowledge.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yl.framework.aspectj.lang.annotation.Log;
import com.yl.framework.aspectj.lang.enums.BusinessType;
import com.yl.project.lvyou.knowledge.domain.QaKnowledge;
import com.yl.project.lvyou.knowledge.service.IQaKnowledgeService;
import com.yl.framework.web.controller.BaseController;
import com.yl.framework.web.domain.AjaxResult;
import com.yl.common.utils.poi.ExcelUtil;
import com.yl.framework.web.page.TableDataInfo;

/**
 * 咨询问答知识库Controller
 * 
 * @author yl
 * @date 2025-03-16
 */
@Controller
@RequestMapping("/lvyou/knowledge")
public class QaKnowledgeController extends BaseController
{
    private String prefix = "scenemanager/knowledge";

    @Autowired
    private IQaKnowledgeService qaKnowledgeService;

    @RequiresPermissions("scenemanager:knowledge:view")
    @GetMapping()
    public String knowledge()
    {
        return prefix + "/knowledge";
    }

    /**
     * 查询咨询问答知识库列表
     */
    @RequiresPermissions("scenemanager:knowledge:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QaKnowledge qaKnowledge)
    {
        startPage();
        List<QaKnowledge> list = qaKnowledgeService.selectQaKnowledgeList(qaKnowledge);
        return getDataTable(list);
    }

    /**
     * 导出咨询问答知识库列表
     */
    @RequiresPermissions("scenemanager:knowledge:export")
    @Log(title = "咨询问答知识库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QaKnowledge qaKnowledge)
    {
        List<QaKnowledge> list = qaKnowledgeService.selectQaKnowledgeList(qaKnowledge);
        ExcelUtil<QaKnowledge> util = new ExcelUtil<QaKnowledge>(QaKnowledge.class);
        return util.exportExcel(list, "knowledge");
    }

    /**
     * 新增咨询问答知识库
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存咨询问答知识库
     */
    @RequiresPermissions("scenemanager:knowledge:add")
    @Log(title = "咨询问答知识库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QaKnowledge qaKnowledge)
    {
        return toAjax(qaKnowledgeService.insertQaKnowledge(qaKnowledge));
    }

    /**
     * 修改咨询问答知识库
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        QaKnowledge qaKnowledge = qaKnowledgeService.selectQaKnowledgeById(id);
        mmap.put("qaKnowledge", qaKnowledge);
        return prefix + "/edit";
    }

    /**
     * 修改保存咨询问答知识库
     */
    @RequiresPermissions("scenemanager:knowledge:edit")
    @Log(title = "咨询问答知识库", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QaKnowledge qaKnowledge)
    {
        return toAjax(qaKnowledgeService.updateQaKnowledge(qaKnowledge));
    }

    /**
     * 删除咨询问答知识库
     */
    @RequiresPermissions("scenemanager:knowledge:remove")
    @Log(title = "咨询问答知识库", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(qaKnowledgeService.deleteQaKnowledgeByIds(ids));
    }

    @GetMapping("/selectScenic")
    public String selectScenic(){
        return prefix + "/spot";
    }


}
